package UDP;

import java.net.*;
import java.util.Scanner;

public class Client {
    public static void main(String[] args) throws Exception {

        //UDP通信
        DatagramSocket socket= new DatagramSocket();
        Scanner sc=new Scanner(System.in);
        while (true) {
            System.out.println("请说");
            String msg=sc.nextLine();
            if(msg.equals("exit")){
                System.out.println("退出成功");
                socket.close();
                break;
            }
            //1.封装的数据
            //2.发出数据大小
            //3.服务器IP地址
            //4.服务端程序端口
            byte[] bytes= msg.getBytes();
            DatagramPacket packet = new DatagramPacket(bytes, bytes.length, InetAddress.getLocalHost(), 6666);
            socket.send(packet);
        }
        //System.out.println("数据发送完毕");
        //socket.close();
    }
}
